/******************************************************************************
 * Copyright (C) 2009 Peter ZHOU <peterzhoulei@gmail.com>                     *
 *                                                                            *
 * This program is free software; you can redistribute it and/or              *
 * modify it under the terms of the GNU General Public License as             *
 * published by the Free Software Foundation; either version 2 of             *
 * the License, or (at your option) any later version.                        *
 *                                                                            *
 * This program is distributed in the hope that it will be useful,            *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU General Public License for more details.                               *
 *                                                                            *
 * You should have received a copy of the GNU General Public License          *
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.      *
 ******************************************************************************/

#import <Cocoa/Cocoa.h>
#import <InputMethodKit/InputMethodKit.h>
#import "ddIM_dict.h"
#import "ddIM_network.h"

IMKServer* ddim_server;
IMKCandidates* candidates = nil;
ddIM_dict* dict;
bool eneng;
bool ining;
NSString* account;
NSString* password;

const NSString* connectionName = @"ddIM_Connection";

int main(int argc, char *argv[])
{
	NSString* identifier;
	NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
	identifier = [[NSBundle mainBundle] bundleIdentifier];
	ddim_server = [[IMKServer alloc] initWithName:(NSString*)connectionName bundleIdentifier:[[NSBundle mainBundle] bundleIdentifier]];
	[NSBundle loadNibNamed:@"MainMenu" owner:[NSApplication sharedApplication]];
	//type = singleRow
	candidates = [[IMKCandidates alloc]  initWithServer:ddim_server panelType:3];
	NSMutableDictionary* attr;
	attr = [NSMutableDictionary dictionaryWithDictionary:[candidates attributes]];
	[attr setValue:[NSColor blueColor] forKey:NSForegroundColorAttributeName];
//	[attr setValue:[NSColor blackColor] forKey:NSBackgroundColorDocumentAttribute];
	[candidates setAttributes:attr];
	dict = [[ddIM_dict alloc] init];
	[dict readPreferences];
	NSLog(@"Reading Preferences Finished");
	[dict readDictFile];
	NSLog(@"Reading Dictionary Finished");
	ddIM_network* newConnection = [[ddIM_network alloc] init]; //update the dictionary
	[newConnection connectToServer];
	[[NSApplication sharedApplication] run];
	[ddim_server release];
	[candidates release];
	[dict release];
	[pool release];
    return 0;
}
